/*
 * 
 * Created on Sep 27, 2005
 */
package com.wgo.precise.client.ui.controller;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * 
 * 
 * @author Petter L. H. Eide
 * @version $Id: PropertyAccessor.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 */
public class PropertyAccessor {
    
    private static final String PLUGIN_BUNDLE_NAME = "/plugin.properties" ;
    private static final String PLUGIN_KEY_PREFIX = "com.wgo.precise.ui." ;
    
     private static final InputStream fis = PropertyAccessor.class.getResourceAsStream(PLUGIN_BUNDLE_NAME);
    
    private static ResourceBundle RESOURCE_BUNDLE;

    static {
    	try {
        	RESOURCE_BUNDLE = new PropertyResourceBundle(fis);    		
    	} catch (IOException e) {
    		System.out.println("Could not load properties..");
    	}
    }
    
    private PropertyAccessor() {
    }

    public static String getString(String key) {
        // TODO Auto-generated method stub
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
        	String message = '!' + key + '!';
//        	RequirementPlugin.log(e, message, PropertyAccessor.class);
            return message;
        }
    }

    public static String getFormattedString(String key, Object arg) { 
        String format= null; 
        try { 
            format= RESOURCE_BUNDLE.getString(key); 
        } catch (MissingResourceException e) { 
        	String message = '!' + key + '!';
//        	RequirementPlugin.log(e, message, PropertyAccessor.class);
            return message;
//            return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ 
        } 
        if (arg == null) 
            arg= ""; //$NON-NLS-1$ 
        return MessageFormat.format(format, new Object[] { arg }); 
    }
    
    public static String getFormattedString (String key, String[] args) { 
        return MessageFormat.format(RESOURCE_BUNDLE.getString(key), new Object[] {args}); //TODO: test if this works, else use next line 
    }
    
    public static String getLocalString(String key) {
    	return getString(PLUGIN_KEY_PREFIX + key);
    }
}
/**
 * Changelog:
 * 
 * $Log: PropertyAccessor.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.2  2005-10-11 15:06:59  petterei
 * Seccond iteration:
 * 1. Eclipse based client with new domain model
 * 2. Flexible Project and Category hierarchy with Drag-n-Drop functionality
 * New functionality:
 * 3. Eclipse plugin update-site
 *
 * Revision 1.1  2005/10/02 21:31:16  petterei
 * client with new domain model
 *
 * Revision 1.1  2005/09/27 17:04:29  petterei
 * inittial commit
 *
 * 
 * 
 */